```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis分页插件原理详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.8;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .code-block {
            background-color: #2d2d2d;
            color: #f8f8f2;
            border-radius: 8px;
            position: relative;
        }
        .code-header {
            background-color: #1e1e1e;
            padding: 8px 16px;
            border-top-left-radius: 8px;
            border-top-right-radius: 8px;
            display: flex;
            align-items: center;
        }
        .code-dots {
            display: flex;
            gap: 6px;
        }
        .code-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
        }
        .dot-red {
            background-color: #ff5f56;
        }
        .dot-yellow {
            background-color: #ffbd2e;
        }
        .dot-green {
            background-color: #27c93f;
        }
        .code-body {
            padding: 16px;
            overflow-x: auto;
        }
        .highlight {
            position: relative;
        }
        .highlight::after {
            content: "";
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 20%;
            background-color: rgba(167, 119, 227, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover::after {
            height: 40%;
            background-color: rgba(167, 119, 227, 0.3);
        }
        .section-divider {
            position: relative;
            height: 1px;
            background: linear-gradient(90deg, transparent, rgba(110, 142, 251, 0.5), transparent);
            margin: 60px 0;
        }
        .card {
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 md:py-32 px-6">
        <div class="max-w-4xl mx-auto text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6 font-serif">MyBatis分页插件原理详解</h1>
            <p class="text-xl md:text-2xl opacity-90 mb-8 max-w-3xl mx-auto">
                揭秘拦截器机制如何实现高效分页查询
            </p>
            <div class="flex justify-center space-x-4">
                <a href="#overview" class="px-6 py-3 bg-white text-purple-700 rounded-full font-medium hover:bg-opacity-90 transition duration-300">
                    核心原理
                </a>
                <a href="#implementation" class="px-6 py-3 bg-transparent border-2 border-white text-white rounded-full font-medium hover:bg-white hover:bg-opacity-10 transition duration-300">
                    实现细节
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <div class="max-w-5xl mx-auto px-6 py-12">
        <!-- Overview Section -->
        <section id="overview" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-purple-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800 font-serif">原理概述</h2>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-10 card">
                <div class="p-8">
                    <p class="text-lg text-gray-700 mb-6">
                        MyBatis 分页插件通过拦截 SQL 查询过程，动态生成适合数据库的分页 SQL 语句，并处理分页结果的封装。这种方式简化了分页查询的开发工作，提高了代码的可维护性和可读性。
                    </p>
                    <div class="flex items-start">
                        <div class="text-purple-500 mr-3 mt-1">
                            <i class="fas fa-lightbulb text-2xl"></i>
                        </div>
                        <div>
                            <p class="text-gray-600">
                                <span class="highlight">底层是通过拦截器实现的，拦截底层通过一个责任链模式+动态代理+反射机制。</span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>

            <div class="grid md:grid-cols-2 gap-8 mb-12">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 mr-4">
                                <i class="fas fa-code-branch"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">拦截SQL语句</h3>
                        </div>
                        <p class="text-gray-600">
                            分页插件实现了 MyBatis 的 <code class="bg-gray-100 px-2 py-1 rounded">Interceptor</code> 接口，拦截 <code class="bg-gray-100 px-2 py-1 rounded">Executor</code> 的 <code class="bg-gray-100 px-2 py-1 rounded">query</code> 方法，捕获执行 SQL 查询的过程。
                        </p>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="w-10 h-10 bg-blue-100 rounded-full flex items-center justify-center text-blue-600 mr-4">
                                <i class="fas fa-edit"></i>
                            </div>
                            <h3 class="text-xl font-semibold text-gray-800">修改SQL语句</h3>
                        </div>
                        <p class="text-gray-600">
                            在拦截到的 SQL 语句中，插件会根据分页参数动态地修改 SQL 语句，添加分页条件，如 <code class="bg-gray-100 px-2 py-1 rounded">LIMIT</code>, <code class="bg-gray-100 px-2 py-1 rounded">OFFSET</code> 或数据库特定的分页语法。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Workflow Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-blue-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800 font-serif">分页插件的工作流程</h2>
            </div>

            <div class="grid md:grid-cols-4 gap-6 mb-12">
                <div class="bg-white rounded-xl shadow-md p-6 text-center card">
                    <div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center text-purple-600 mx-auto mb-4">
                        <i class="fas fa-search text-2xl"></i>
                    </div>
                    <h3 class="text-lg font-semibold mb-2">1. 拦截SQL语句</h3>
                    <p class="text-gray-600 text-sm">捕获SQL查询过程</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 text-center card">
                    <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center text-blue-600 mx-auto mb-4">
                        <i class="fas fa-magic text-2xl"></i>
                    </div>
                    <h3 class="text-lg font-semibold mb-2">2. 修改SQL语句</h3>
                    <p class="text-gray-600 text-sm">添加分页条件</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 text-center card">
                    <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center text-green-600 mx-auto mb-4">
                        <i class="fas fa-database text-2xl"></i>
                    </div>
                    <h3 class="text-lg font-semibold mb-2">3. 执行分页查询</h3>
                    <p class="text-gray-600 text-sm">数据库执行修改后的SQL</p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-6 text-center card">
                    <div class="w-16 h-16 bg-yellow-100 rounded-full flex items-center justify-center text-yellow-600 mx-auto mb-4">
                        <i class="fas fa-box-open text-2xl"></i>
                    </div>
                    <h3 class="text-lg font-semibold mb-2">4. 封装结果</h3>
                    <p class="text-gray-600 text-sm">返回分页数据对象</p>
                </div>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-10 card">
                <div class="p-8">
                    <h3 class="text-xl font-semibold text-gray-800 mb-4">SQL修改示例</h3>
                    <div class="grid md:grid-cols-2 gap-6">
                        <div>
                            <p class="text-gray-700 font-medium mb-2">原始SQL:</p>
                            <div class="code-block">
                                <div class="code-header">
                                    <div class="code-dots mr-3">
                                        <div class="code-dot dot-red"></div>
                                        <div class="code-dot dot-yellow"></div>
                                        <div class="code-dot dot-green"></div>
                                    </div>
                                    <span class="text-gray-400 text-sm">SQL</span>
                                </div>
                                <div class="code-body">
                                    <pre class="text-sm">SELECT * FROM users WHERE status = 'active'</pre>
                                </div>
                            </div>
                        </div>
                        <div>
                            <p class="text-gray-700 font-medium mb-2">分页SQL (MySQL):</p>
                            <div class="code-block">
                                <div class="code-header">
                                    <div class="code-dots mr-3">
                                        <div class="code-dot dot-red"></div>
                                        <div class="code-dot dot-yellow"></div>
                                        <div class="code-dot dot-green"></div>
                                    </div>
                                    <span class="text-gray-400 text-sm">SQL</span>
                                </div>
                                <div class="code-body">
                                    <pre class="text-sm">SELECT * FROM users WHERE status = 'active' LIMIT 0, 10</pre>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Implementation Section -->
        <section id="implementation" class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-green-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800 font-serif">插件实现示例</h2>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-10 card">
                <div class="p-8">
                    <div class="code-block">
                        <div class="code-header">
                            <div class="code-dots mr-3">
                                <div class="code-dot dot-red"></div>
                                <div class="code-dot dot-yellow"></div>
                                <div class="code-dot dot-green"></div>
                            </div>
                            <span class="text-gray-400 text-sm">Java</span>
                        </div>
                        <div class="code-body">
                            <pre class="text-sm"><code>public class PaginationInterceptor implements Interceptor {

    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        // 获取原始的 SQL 语句
        MappedStatement mappedStatement = (MappedStatement) invocation.getArgs()[0];
        BoundSql boundSql = (BoundSql) invocation.getArgs()[1];
        String sql = boundSql.getSql();
        
        // 从参数中获取分页信息（如页码、每页记录数）
        Integer pageNum = getPageNumberFromParameters(invocation.getArgs());
        Integer pageSize = getPageSizeFromParameters(invocation.getArgs());
        
        // 根据数据库类型生成分页 SQL
        String paginatedSql = getPaginatedSql(sql, pageNum, pageSize);
        
        // 替换原始 SQL
        BoundSql newBoundSql = copyFromBoundSql(mappedStatement, boundSql, paginatedSql);
        // 重新设置 BoundSql
        Configuration configuration = mappedStatement.getConfiguration();
        MappedStatement newStatement = copyFromMappedStatement(mappedStatement, new BoundSqlSqlSource(newBoundSql));
        
        // 执行分页查询
        return invocation.proceed();
    }
    
    private String getPaginatedSql(String sql, Integer pageNum, Integer pageSize) {
        // 根据数据库类型生成分页 SQL
        // For MySQL: "SELECT * FROM (original SQL) LIMIT offset, limit"
        return sql + " LIMIT " + (pageNum - 1) * pageSize + ", " + pageSize;
    }
    
    // 复制 BoundSql 对象
    private BoundSql copyFromBoundSql(MappedStatement mappedStatement, BoundSql boundSql, String sql) {
        BoundSql newBoundSql = new BoundSql(mappedStatement.getConfiguration(), sql, boundSql.getParameterMappings(), boundSql.getParameterObject());
        return newBoundSql;
    }
    
    // 复制 MappedStatement 对象
    private MappedStatement copyFromMappedStatement(MappedStatement ms, SqlSource newSqlSource) {
        MappedStatement.Builder builder = new MappedStatement.Builder(ms.getConfiguration(), ms.getId(), newSqlSource, ms.getSqlCommandType());
        return builder.build();
    }
    
    @Override
    public Object plugin(Object target) {
        return Plugin.wrap(target, this);
    }

    @Override
    public void setProperties(Properties properties) {}
}</code></pre>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Features Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-yellow-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800 font-serif">分页插件的主要特性</h2>
            </div>

            <div class="grid md:grid-cols-3 gap-8">
                <div class="bg-white rounded-xl shadow-md p-8 card">
                    <div class="text-purple-600 mb-4">
                        <i class="fas fa-bolt text-3xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">动态SQL修改</h3>
                    <p class="text-gray-600">
                        根据分页参数动态生成适合特定数据库的分页SQL语句，适配不同数据库的分页语法。
                    </p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-8 card">
                    <div class="text-blue-600 mb-4">
                        <i class="fas fa-server text-3xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">支持多种数据库</h3>
                    <p class="text-gray-600">
                        通过数据库类型选择合适的分页SQL语法，兼容MySQL、Oracle、SQL Server等多种数据库。
                    </p>
                </div>
                <div class="bg-white rounded-xl shadow-md p-8 card">
                    <div class="text-green-600 mb-4">
                        <i class="fas fa-boxes text-3xl"></i>
                    </div>
                    <h3 class="text-xl font-semibold mb-3">封装分页结果</h3>
                    <p class="text-gray-600">
                        将分页结果封装成包含分页信息和数据列表的对象，方便后续处理和展示。
                    </p>
                </div>
            </div>
        </section>

        <!-- Plugin Class Section -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-red-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800 font-serif">Plugin类解析</h2>
            </div>

            <div class="mb-8">
                <p class="text-gray-700 mb-6">
                    Plugin的wrap方法，它根据当前的Interceptor上面的注解定义哪些接口需要拦截，然后判断当前目标对象是否有实现对应需要拦截的接口，如果没有则返回目标对象本身，如果有则返回一个代理对象。而这个代理对象的InvocationHandler正是一个Plugin。
                </p>
                <p class="text-gray-700">
                    当目标对象在执行接口方法时，如果是通过代理对象执行的，则会调用对应InvocationHandler的invoke方法，也就是Plugin的invoke方法。如果当前执行的方法是定义好的需要拦截的方法，则把目标对象、要执行的方法以及方法参数封装成一个Invocation对象，再把封装好的Invocation作为参数传递给当前拦截器的intercept方法。
                </p>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">Plugin类核心代码</h3>
                        <div class="code-block">
                            <div class="code-header">
                                <div class="code-dots mr-3">
                                    <div class="code-dot dot-red"></div>
                                    <div class="code-dot dot-yellow"></div>
                                    <div class="code-dot dot-green"></div>
                                </div>
                                <span class="text-gray-400 text-sm">Java</span>
                            </div>
                            <div class="code-body">
                                <pre class="text-sm"><code>package org.apache.ibatis.plugin;
class Plugin implements InvocationHandler {

    public static Object wrap(Object target, Interceptor interceptor) {
        // 省略
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 省略
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                    <div class="p-6">
                        <h3 class="text-xl font-semibold mb-4">拦截器实现示例</h3>
                        <div class="code-block">
                            <div class="code-header">
                                <div class="code-dots mr-3">
                                    <div class="code-dot dot-red"></div>
                                    <div class="code-dot dot-yellow"></div>
                                    <div class="code-dot dot-green"></div>
                                </div>
                                <span class="text-gray-400 text-sm">Java</span>
                            </div>
                            <div class="code-body">
                                <pre class="text-sm"><code>@Component
@Intercepts({@Signature( type = StatementHandler.class, method = "query",
                args = {Statement.class, ResultHandler.class})})
public class MyMyBatisInterceptor implements Interceptor {
    public Object intercept(Invocation invocation) throws Throwable {
        System.out.println("MyMyBatisInterceptor.intercept1");
        Object returnObject = invocation.proceed();
        System.out.println("MyMyBatisInterceptor.intercept2");
        return returnObject;
    }

    @Override
    public Object plugin(Object target) {
        System.out.println("MyMyBatisInterceptor.plugin");
        return Plugin.wrap(target, this);
    }
}</code></pre>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Popular Plugins -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-indigo-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800 font-serif">常用分页插件</h2>
            </div>

            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                    <div class="p-8">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 bg-purple-100 rounded-lg flex items-center justify-center text-purple-600 mr-4">
                                <i class="fab fa-java text-2xl"></i>
                            </div>
                            <h3 class="text-xl font-semibold">MyBatis-Plus</h3>
                        </div>
                        <p class="text-gray-600 mb-4">
                            MyBatis-Plus自带分页插件，简化了分页处理，提供了丰富的API和配置选项，支持多种数据库。
                        </p>
                        <div class="flex items-center text-sm text-purple-600">
                            <i class="fas fa-link mr-2"></i>
                            <a href="https://baomidou.com/" target="_blank" class="hover:underline">官方文档</a>
                        </div>
                    </div>
                </div>
                <div class="bg-white rounded-xl shadow-md overflow-hidden card">
                    <div class="p-8">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 bg-blue-100 rounded-lg flex items-center justify-center text-blue-600 mr-4">
                                <i class="fas fa-pager text-2xl"></i>
                            </div>
                            <h3 class="text-xl font-semibold">PageHelper</h3>
                        </div>
                        <p class="text-gray-600 mb-4">
                            另一种流行的MyBatis分页插件，支持多种数据库，配置简单，使用方便，广泛应用于MyBatis项目中。
                        </p>
                        <div class="flex items-center text-sm text-blue-600">
                            <i class="fas fa-link mr-2"></i>
                            <a href="https://github.com/pagehelper/Mybatis-PageHelper" target="_blank" class="hover:underline">GitHub仓库</a>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Visualization -->
        <section class="mb-20">
            <div class="flex items-center mb-8">
                <div class="w-12 h-1 bg-teal-500 mr-4"></div>
                <h2 class="text-3xl font-bold text-gray-800 font-serif">工作原理示意图</h2>
            </div>

            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card">
                <div class="mermaid">
                    sequenceDiagram
                        participant Client
                        participant Plugin
                        participant Interceptor
                        participant Executor
                        participant Database

                        Client->>Executor: 执行查询
                        Executor->>Plugin: 方法调用
                        Plugin->>Interceptor: intercept()
                        Interceptor->>Executor: 修改SQL(分页)
                        Executor->>Database: 执行分页查询
                        Database-->>Executor: 返回结果
                        Executor-->>Plugin: 返回结果
                        Plugin-->>Interceptor: 结果处理
                        Interceptor-->>Plugin: 封装分页结果
                        Plugin-->>Client: 返回Page对象
                </div>
            </div>
        </section>
    </div>

    <!-- Footer -->
    <footer class="bg-gray-900 text-white py-12 px-6">
        <div class="max-w-5xl mx-auto">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-6 md:mb-0">
                    <h3 class="text-xl font-semibold mb-2">技术小馆</h3>
                    <p class="text-gray-400">深入解析技术原理，助力开发者成长</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" target="_blank" class="text-gray-300 hover:text-white transition duration-300 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        <span>技术小馆地址: http://www.yuque.com/jtostring</span>
                    </a>
                </div>
            </div>
            <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-500 text-sm">
                &copy; 2023 技术小馆. All rights reserved.
            </div>
        </div>
    </footer>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            mermaid.initialize({
                startOnLoad: true,
                theme: 'dark',
                sequence: {
                    actorMargin: 50,
                    showSequenceNumbers: true,
                    useMaxWidth: false
                }
            });
        });
    </script>
</body>
</html>
```